package com.test.mcdonald;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Timer;
import java.util.TimerTask;

public class McDonald {
	static List<Cashier> cashierList = new ArrayList<Cashier>(3);
	public static boolean stopWork;
	private static Queue<ClientMy> clientsList = new LinkedList<ClientMy>();

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		// Tables for dishes
		// Table HamburgerTable = new Table();
		// Table CheeseburgerTable = new Table();
		// Table MacchikenTable = new Table();
		// Table ChippedpotatoTable = new Table();
		// Table IcecreamTable = new Table();
		// // Cooks
		// Cook Cook1 = new Cook("cook1", HamburgerTable);
		// Cook Cook2 = new Cook("cook2", CheeseburgerTable);
		// Cook Cook3 = new Cook("cook3", MacchikenTable);
		// Cook Cook4 = new Cook("cook4", ChippedpotatoTable);
		// Cook Cook5 = new Cook("cook5", IcecreamTable);

		// int count=HamburgerTable.getDishCount();
		// System.out.print(count);
		initCashiersWork();
		createTimerGenerateClients();
		try {
			cashierList.get(0).getCurThread().join();
			cashierList.get(1).getCurThread().join();
			cashierList.get(2).getCurThread().join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	private static void createTimerGenerateClients() {
		Timer timerGenerateClients = new Timer();
		timerGenerateClients.schedule(new TimerTask() {

			@Override
			public void run() {
				initClients();
			}
		}, 0, GlobalSettings.TIME_SHOULD_CREATE_CLIENTS);
	}

	private static void initCashiersWork() {
		// TODO Auto-generated method stub
		Cashier cashier1 = new Cashier("cashier1");
		Cashier cashier2 = new Cashier("cashier2");
		Cashier cashier3 = new Cashier("cashier3");
		cashierList.add(cashier1);
		cashierList.add(cashier2);
		cashierList.add(cashier3);
		// cashier1.setTimeBusy(1000);
		// //cashier1.setBusy();
		// cashier2.setTimeBusy(500);
		// cashier3.setTimeBusy(700);

	}

	private static void initClients() {
		if (GlobalSettings.MAX_CLIENTS < clientsList.size()) {
			System.out.print(" Method: initClients"
					+ " the restaurant is full (over " + GlobalSettings.MAX_CLIENTS
					+ " clients).\n");
		} else {
			int numClients = GlobalSettings.getNumGeneratedClients();
			for (int i = 0; i < numClients; i++) {
				ClientMy client = new ClientMy();
				clientsList.add(client);
			}
			System.out.print(" Method: initClients" + " Generated "
					+ numClients + " clients " + "\n");
		}
	}

}
